import {listArticle} from "@/pages/article/service";

const ArticleModel = {
  // 命名空间就是把多个model区分开
  namespace: 'article',
  // state是个模块的数据
  state: {
    list: [],
    listLoading: false
  },
  // 涉及到有副作用的操作，会放在这里
  // 通过generator解决的异步问题
  effects: {
    * initListData(action, {call, put}) {
      yield put({
        type: "changeListLoading",
        loading: true
      })
      const response = yield call(listArticle, action.params);
      yield put({
        type: "changeList",
        payload: {
          list: response.rows,
          total: response.total
        }
      })
      yield put({
        type: "changeListLoading",
        loading: false
      })
    }
  },
  reducers: {
    changeList(state, {payload}) {
      return {
        ...state,
        ...payload
      }
    },
    changeListLoading(state, {loading}) {
      return {
        ...state,
        listLoading:loading
      }
    }
  },
};
export default ArticleModel;
